package view.employee;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dal.employee.Employee;
import dal.employee.EmployeeUtil;

/**
 * Servlet implementation class ViewByIdEmployee
 */
@WebServlet("/ViewByIdEmployee")
public class ViewByIdEmployee extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ViewByIdEmployee() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter printWriter = response.getWriter();
		// response.setContentType("text/HTML");
		try {

			Employee employee = new Employee();
			String ViewByIdEmployee = request.getParameter("ViewByIdEmployee");

			EmployeeUtil employeeUtil = new EmployeeUtil();
			System.out.println("Redirect");

			// employee.setEmployeeId(ViewByIdEmployee);

			Object object = employeeUtil.get(ViewByIdEmployee);
			HttpSession session = request.getSession();
			session.setAttribute("employee", object);
			System.out.println("In servlet" + object);

			request.getRequestDispatcher("EmployeeViewById.jsp").forward(
					request, response);

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			printWriter.print("" + "<b>" + " Requested Information is not Present " + "</b>");

			
		}
	}

}
